#!/usr/bin/env ksh
#
# dnscrypt-proxy switcher
#
# <bitbar.author.github>jedisct1</bitbar.author.github>
# <bitbar.author>Frank Denis</bitbar.author>
# <bitbar.desc>Toggle dnscrypt-proxy usage</bitbar.desc>
# <bitbar.image>https://raw.githubusercontent.com/jedisct1/bitbar-dnscrypt-proxy-switcher/master/bitbar-dnscrypt-proxy.jpg</bitbar.image>
# <bitbar.title>dnscrypt-proxy switcher</bitbar.title>
# <bitbar.url>https://github.com/jedisct1/bitbar-dnscrypt-proxy-switcher</bitbar.url>
# <bitbar.version>v0.1</bitbar.version>

# Theme: classic or emoji
THEME="emoji"

# Non-authenticated resolver IP addresses
ADDITIONAL_IPS="9.9.9.9"

# Name of the non-authenticated resolver
ADDITIONAL_NAME="quad9"

# IP address of the proxy
DNSCRYPT_PROXY_IPS="127.0.0.1"

# -- do not change anything below this line --

if test -t 0; then
	THEME="emoji"
fi

case "$THEME" in
classic)
	PROXY_ICON="| dropdown=false templateImage=JVBERi0xLjMKJcTl8uXrp/Og0MTGCjQgMCBvYmoKPDwgL0xlbmd0aCA1IDAgUiAvRmlsdGVyIC9GbGF0ZURlY29kZSA+PgpzdHJlYW0KeAFlVEuqHDEM3PcpvA7E0cey5XVO8FY5QEN4gUkgvPtDSn4td0OYoUddsqSSVJ6/5a38LVS4l9/xwPcVD8IPred7en98KX/CNWpz7e06r5VHVyuvI6JbHTpcPw1zXinzCA6cRaoLov2qVKULDwREyRWOqANmBp3Ad0xw4h0Co/F8+gkFvJoPF8CvsJld7aAq+JWpgNogcy9Um0nvOp5Qn51o8dznuDZxZVnplI1NDmAg3SIbm4sMsGqMQVhBY2mepVXt3PiBbWe6Vq4r8rxjmWtXN3+kaGjMpUWFNBGAhBTbSOyAIdSaFZZKNDCgcBlPcKt9mvnElNgqyxyreZ6zSSBdBkVPRNTZY6G5awTcL6/yHqeVHfNs2D8Rpgj5JGaYtlhbUrqwo4NDH7Y0IgY+yN1jFeAndWJ6fiOrry7d240xVeva5JHpQsquh7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MAowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDU2NTkgMDAwMDAgbiAKMDAwMDAwMDUwNSAwMDAwMCBuIAowMDAwMDA1NDIwIDAwMDAwIG4gCjAwMDAwMDAwMjIgMDAwMDAgbiAKMDAwMDAwMDQ4NiAwMDAwMCBuIAowMDAwMDAwNjA3IDAwMDAwIG4gCjAwMDAwMDA3MzEgMDAwMDAgbiAKMDAwMDAwMTMwMyAwMDAwMCBuIAowMDAwMDAxMzIyIDAwMDAwIG4gCjAwMDAwMDUzODMgMDAwMDAgbiAKMDAwMDAwMTM5MSAwMDAwMCBuIAowMDAwMDAyNjEwIDAwMDAwIG4gCjAwMDAwMDE0MzkgMDAwMDAgbiAKMDAwMDAwMjU4OSAwMDAwMCBuIAowMDAwMDAyNjQ3IDAwMDAwIG4gCjAwMDAwMDUzNjIgMDAwMDAgbiAKMDAwMDAwNTUwMSAwMDAwMCBuIAowMDAwMDA1NTY1IDAwMDAwIG4gCjAwMDAwMDU2MTcgMDAwMDAgbiAKdHJhaWxlcgo8PCAvU2l6ZSAyMCAvUm9vdCAxNyAwIFIgL0luZm8gMSAwIFIgL0lEIFsgPDY3NGRkZmQ4MGY5ZTc3Yzg4ZDhjNjZhMTJhYTk4NTk0Pgo8Njc0ZGRmZDgwZjllNzdjODhkOGM2NmExMmFhOTg1OTQ+IF0gPj4Kc3RhcnR4cmVmCjU3MzQKJSVFT0YK"
	;;
*)
	PROXY_ICON='🔒'
	PROXY_ADDITIONAL_ICON='🔓'
	OTHER_ICON='🤷'
	ADDITIONAL_ICON='☘'
	ERROR_ICON='🧟'
	;;
esac

osversion=$(sw_vers -productVersion)
osmajor=$(echo "$osversion" | awk -F. '{print $1}')
osminor=$(echo "$osversion" | awk -F. '{print $2}')
ospatch=$(echo "$osversion" | awk -F. '{print $3}')
[[ "$osmajor" -eq 10 && "$osminor" -lt 7 ]] && exit 14
[ "$osmajor" -lt 10 ] && exit 15

get_current_service() {
	services=$(networksetup -listnetworkserviceorder | grep -F 'Hardware Port')
	echo "$services" | while read -r line; do
		sname=$(echo "$line" | awk -F "(, )|(: )|[)]" '{print $2}')
		sdev=$(echo "$line" | awk -F "(, )|(: )|[)]" '{print $4}')
		if [ -n "$sdev" ]; then
			ifout="$(ifconfig "$sdev" 2>/dev/null)"
			if echo "$ifout" | grep -Fq 'status: active'; then
				currentservice="$sname"
				break
			fi
		fi
	done

	if [ -n "$currentservice" ]; then
		echo "$currentservice"
	else
		exit 1
	fi
}

get_service_resolvers() {
	service="$1"
	ips=""
	for ip in $(networksetup -getdnsservers "$service" | sort -u); do
		if [ "$ips" ]; then
			ips="$ips "
		fi
		ips="$ips$ip"
	done
	echo "$ips"
}

get_current_resolvers() {
	[ -r /etc/resolv.conf ] || exit 0
	ips_i=""
	sort -u /etc/resolv.conf | while read -r line; do
		case "$line" in
		nameserver\ *)
			ip=$(echo "$line" | sed -e 's/nameserver *//' -e 's/ *//')
			ips_i="$ips_i $ip"
			;;
		esac
	done

	typeset -A found
	ips=""
	for ip_i in $ips_i; do
		# shellcheck disable=SC2086
		if [ ! ${found["$ip_i"]} ]; then
			if [ "$ips" ]; then
				ips="$ips "
			fi
			ips="$ips$ip_i"
			found["$ip_i"]=1
		fi
	done

	echo "$ips"
}

flush_dns_cache() {
	if [ "$osmajor" -eq 10 ]; then
		if [ "$osminor" -le 8 ]; then
			killall -HUP mDNSResponder 2>/dev/null
		elif [ "$osminor" = 9 ]; then
			dscacheutil -flushcache 2>/dev/null
			killall -HUP mDNSResponder 2>/dev/null
		elif [ "$osminor" = 10 ]; then
			if [ "$ospatch" -le 3 ]; then
				discoveryutil mdnsflushcache 2>/dev/null
				discoveryutil udnsflushcaches 2>/dev/null
			else
				dscacheutil -flushcache 2>/dev/null
				killall -HUP mDNSResponder 2>/dev/null
			fi
		elif [ "$osminor" = 11 ]; then
			dscacheutil -flushcache 2>/dev/null
			killall -HUP mDNSResponder 2>/dev/null
		elif [ "$osminor" = 12 ]; then
			if [ "$ospatch" -le 2 ]; then
				killall -HUP mDNSResponder 2>/dev/null
			else
				killall -HUP mDNSResponder 2>/dev/null
				killall mDNSResponderHelper 2>/dev/null
				dscacheutil -flushcache 2>/dev/null
			fi
		elif [ "$osminor" = 15 ]; then
			dscacheutil -flushcache 2>/dev/null
			killall -HUP mDNSResponder 2>/dev/null
		else
			killall -HUP mDNSResponder 2>/dev/null
		fi
	elif [ "$osmajor" -eq 11 ]; then
		dscacheutil -flushcache 2>/dev/null
		killall -HUP mDNSResponder 2>/dev/null
	fi
}

display_name_for_resolvers() {
	resolvers="$1"
	case "$resolvers" in
	"$DNSCRYPT_PROXY_IPS") echo "dnscrypt-proxy" ;;
	"${DNSCRYPT_PROXY_IPS} ${ADDITIONAL_IPS}") echo "dnscrypt-proxy + ${ADDITIONAL_NAME}" ;;
	"$ADDITIONAL_IPS") echo "$ADDITIONAL_NAME" ;;
	^$ | There*) echo "default" ;;
	*) echo "$resolvers" ;;
	esac
}

service=$(get_current_service)
if [ -z "$service" ]; then
	echo "$ERROR_ICON"
	exit 0
fi

if [ "$#" -gt 0 ]; then
	wanted_resolvers="$*"
	# shellcheck disable=2086
	networksetup -setdnsservers "$service" $wanted_resolvers
	flush_dns_cache 2>/dev/null
	exit 0
fi

service_resolvers=$(get_service_resolvers "$service")
current_resolvers=$(get_current_resolvers)
service_resolvers_name=$(display_name_for_resolvers "$service_resolvers")
current_resolvers_name=$(display_name_for_resolvers "$current_resolvers")

if [ "$current_resolvers_name" = "dnscrypt-proxy" ]; then
	echo "$PROXY_ICON"
elif [ "$current_resolvers_name" = "dnscrypt-proxy + ${ADDITIONAL_NAME}" ]; then
	echo "$PROXY_ADDITIONAL_ICON"
elif [ "$current_resolvers_name" = "${ADDITIONAL_NAME}" ]; then
	echo "$ADDITIONAL_ICON"
else
	echo "$OTHER_ICON"
fi
echo "---"

echo "${service} resolvers: ${service_resolvers_name}"
if [ "$service_resolvers_name" != "$current_resolvers_name" ]; then
	echo "Current resolvers: ${current_resolvers_name} | color=red"
fi

echo "Use default DNS | terminal=false refresh=true bash=\"${0}\" param1=empty"
echo "Use dnscrypt-proxy | terminal=false refresh=true bash=\"${0}\" param1='${DNSCRYPT_PROXY_IPS}'"
echo "Use dnscrypt-proxy + ${ADDITIONAL_NAME} | terminal=false refresh=true bash=\"${0}\" param1='${DNSCRYPT_PROXY_IPS} ${ADDITIONAL_IPS}'"
echo "Use ${ADDITIONAL_NAME} | terminal=false refresh=true bash=\"${0}\" param1='${ADDITIONAL_IPS}'"
echo "View the dnscrypt-proxy public servers list | href=https://dnscrypt.info/public-servers"
